<?php namespace Home\Controller; 
//分类
use \Common\Model\Cate;
use \Common\Model\Goods;
use \Common\Model\Brand;
use Hdphp\Controller\Controller;
use \Common\Model\TypeAttr;
//商品属性表
use \Common\Model\GoodsAttr;
//首页控制器
class IndexController extends Controller{
    //动作
    public function index(){
//		地方特产
//		1.获取顶级分类
		$cateModel = new Cate();
//		2.通过当前的cid获得所有的子集id
		$cid = 16;//地方特产的cid
		$cids = $cateModel->getSon($cateModel->get(),$cid);
		$cids[] = $cid;
//		3.根据cid获得商品的gid
		$goodsModel = new Goods();
		$aids = $goodsModel->where("category_cid IN(". implode(',', $cids). ")")->lists('aid');
//		1
		$goodsData = $goodsModel
						->join('brand as b','brand_bid','=','bid')
						->where("aid IN(". implode(',', $aids). ")")
						->orderBy("rand()")
						->limit(10)
						->get();
		View::with('goodsData',$goodsData);		
		
//		2
		$two = $goodsModel
						->join('brand as b','brand_bid','=','bid')
						->where("aid IN(". implode(',', $aids). ")")
						->orderBy("rand()")
						->limit(10)
						->get();
		View::with('two',$two);
//		3
		$three = $goodsModel
						->join('brand as b','brand_bid','=','bid')
						->where("aid IN(". implode(',', $aids). ")")
						->orderBy("rand()")
						->limit(10)
						->get();
		View::with('three',$three);		
//		4
		$four = $goodsModel
						->join('brand as b','brand_bid','=','bid')
						->where("aid IN(". implode(',', $aids). ")")
						->orderBy("rand()")
						->limit(10)
						->get();
		View::with('four',$four);
//		1.获得品牌
		$brandData = $goodsModel
						->join('brand as b','brand_bid','=','bid')
						->orderBy("rand()")
						->groupBy('bname')
						->limit(10)
						->get();
		View::with('brandData',$brandData);
//		2
		$brandTwo = $goodsModel
				->join('brand as b','brand_bid','=','bid')
				->orderBy("rand()")
				->groupBy('bname')
				->limit(10)
				->get();
		View::with('brandTwo',$brandTwo);
		
		
		//今日畅购
		$goods = $goodsModel
					->join('brand as b','brand_bid','=','bid')
					->orderBy("rand()")	
					->limit(10)
					->get();
		$data = $goodsModel
					->join('brand as b','brand_bid','=','bid')
					->orderBy("rand()")	
					->limit(10)
					->get();			
		View::with('goods',$goods);
		View::with('data',$data);
			
       View::make();
    }
}
